/*
  将下面异步代码使用 Promise 的方法改进
  尽量用看上去像同步代码的方式
  setTimeout(function () {
    var a = 'hello'
    setTimeout(function () {
      var b = 'lagou'
      setTimeout(function () {
        var c = 'I ♥ U'
        console.log(a + b +c)
      }, 10)
    }, 10)
  }, 10)
*/

const timeoutFn = function(fn) {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve(fn && fn())
    }, 10);
  });
}

const log = function(a,b,c) {
  console.log(a, b, c);
}

function curry (func) {
  return function curriedFn(...args) {
    // 判断实参和形参的个数
    if (args.length < func.length) {
      return function () {
        return curriedFn(...args.concat(Array.from(arguments)))
      }
    }
    return func(...args)
  }
}

const curried = curry(log);

timeoutFn(curried('hello'))
  .then((resolve) => timeoutFn(resolve('lagou')))
  .then((resolve) => timeoutFn(resolve('I ♥ U')));
